package com.jsbb;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.core.io.ClassPathResource;

import java.util.ArrayList;
import java.util.List;

/**
 * mybatis-generator执行类
 *
 * @author jsbb
 */
public class Generator {

    public static final String AUTHOR = "jsbb";

    public static void main(String[] args) throws Exception {
        generate();
    }

    public static void generate() throws Exception {
        List<String> warnings = new ArrayList<>();
        ConfigurationParser parser = new ConfigurationParser(warnings);
        Configuration config = parser.parseConfiguration(new ClassPathResource("generatorConfig.xml").getFile());
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator generator = new MyBatisGenerator(config, callback, warnings);
        generator.generate(null);
        for (String s : warnings) {
            System.out.println(s);
        }
    }
}
